<?php

defined('SYSPATH') or die('No direct access allowed.');

/**
 * Service Bookmark 
 */
class Model_Service_Bookmark extends Domain_Dao_Bookmark {

    public $_rep;

    /**
     * 
     */
    public function __construct()
    {
        $o_repository_manager = new Domain_Repositories_RepositoryManager;
        $this->_rep = $o_repository_manager->getBookmarkRepository();
    }

    /**
     *
     * @return <type>
     */
    public function load($id)
    {
        return $this->_rep->load($id);
    }

    /**
     *
     * @param <type> $offset
     * @param <type> $limit
     * @param <type> $filter
     * @param <type> $sort
     * @param <type> $count
     * @return <type>
     */
    public function load_all($is_count = false, $offset=null, $limit=null, $filter = null, $sort = null)
    {
        return $this->_rep->load_all($offset, $limit, $filter, $sort, $is_count);
    }

    /**
     *
     * @param Domain_Entities_Entity $o_entity
     * @return <type> 
     */
    public function insert($o_entity)
    {
        return $this->_rep->insert_by($o_entity);
    }

    /**
     *
     * @param Domain_Entities_Entity $o_entity
     * @return <type>
     */
    public function update($o_entity)
    {
        return $this->_rep->update_by($o_entity);
    }

    /**
     *
     * @param <type> $id
     * @return <type> 
     */
    public function delete($id)
    {
        return $this->_rep->delete_by($id);
    }
    /**
     *
     * @param <type> $s_id
     * @return <type>
     */
    public function delete_by_ids($s_id)
    {
        $obj = $this->_rep->db_delete($this->_rep->table_name())
                ->where('item_id', 'in', DB::expr('(' . $s_id . ')'));
        return $this->_rep->db_execute($obj);
    }
    
    public function delete_by_user_ids($s_id)
    {
        $obj = $this->_rep->db_delete($this->_rep->table_name())
                ->where('user_id', 'in', DB::expr('(' . $s_id . ')'));
        return $this->_rep->db_execute($obj);
    }
    public function get($user_id, $item_id) {
        $this->_rep->clear();
        $this->_rep->builder_select('user_id', array('where' => '='), $user_id);
        $this->_rep->builder_select('item_id', array('where' => '='), $item_id);
        return $this->_rep->query();
    }
}

?>
